package com.hczt.springcloud.oauthservice.entity.base;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import java.io.Serializable;
import java.util.Date;

/**
 * 精诚所至，金石为开。
 * 石の上にも三年;陽気の発する所金石亦透る。
 * Faith moves mountains.
 *
 * @author marvin.ma
 * @create 2017-12-11 22:47
 * @desc 数据库实体基类
 **/
@Data
@MappedSuperclass
public class BaseEntity implements Serializable {

    private static final long serialVersionUID = -7326606173399550882L;

    @Column(updatable = false, nullable = false)
    private Date createTime;

    @Column(nullable = false)
    @JsonIgnore
    private Date updateTime;

    @PrePersist
    public void prePersist() {
        createTime = updateTime = new Date();
    }
    @PreUpdate
    public void preUpdate() {
        updateTime = new Date();
    }
}
